<template>
  <view class="container"  >
    <view
      class="list_cell m_t mem_avatar_wrap flex_row_between_center"
      hover-class="cell_hover"
      :hover-stay-time="50"
      @click="setAvatar"
    >
      <text class="cell_tit">修改会员头像</text>
      <view class="flex_row_end_center">
        <view
          class="avatar"
          :style="{
            backgroundImage: 'url(' + memberAvatar + ')',
            backgroundSize: 'cover'
          }"
        />
        <text class="cell_more iconfont iconziyuan11"></text>
      </view>
    </view>

    <view class="list_cell m_t" hover-class="cell_hover" :hover-stay-time="50">
      <text class="cell_tit">会员名</text>
      <view>
        <text class="cell_right_con">{{ memberName }}</text>
      </view>
    </view>

    <view
      class="list_cell b_b m_t"
      @click="changeName('true')"
      hover-class="cell_hover"
      :hover-stay-time="50"
    >
      <text class="cell_tit">{{ '真实姓名' }}</text>
      <view>
        <text class="cell_right_con">{{
          memberTrueName ? memberTrueName : '--'
        }}</text>
        <text class="cell_more iconfont iconziyuan11"></text>
      </view>
    </view>
    <view
      class="list_cell b_b"
      @click="changeName('nick')"
      hover-class="cell_hover"
      :hover-stay-time="50"
    >
      <text class="cell_tit">昵称</text>
      <view>
        <text class="cell_right_con">{{
          memberNickName ? memberNickName : '--'
        }}</text>
        <text class="cell_more iconfont iconziyuan11"></text>
      </view>
    </view>
    <view hover-class="cell_hover" :hover-stay-time="50">
      <picker @change="selSex" :value="gender" :range="sexArray">
        <view class="list_cell b_b">
          <text class="cell_tit">性别</text>
          <view class="flex_row_end_center">
            <view class="uni_birthday">{{ sexArray[gender] }}</view>
            <text class="cell_more iconfont iconziyuan11"></text>
          </view>
        </view>
      </picker>
    </view>
    <view hover-class="cell_hover" :hover-stay-time="50">
      <picker
        mode="date"
        :end="filters.getDateTime(endtime)"
        :value="memberBirthday"
        @change="selBirthDay"
      >
        <view class="list_cell">
          <text class="cell_tit">生日</text>
          <view class="flex_row_end_center">
            <view class="uni_birthday">{{ memberBirthdayCon }}</view>
            <text class="cell_more iconfont iconziyuan11"></text>
          </view>
        </view>
      </picker>
    </view>

	
  </view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import filters from '@/utils/filter.js'
export default {
  data() {
    return {
      memberAvatarLocal: '',
      memberAvatar:"https://sy-hws-file-oss.oss-cn-beijing.aliyuncs.com/yijing/logo.png" , //会员头像
      memberName: '',
      memberNickName: '', //昵称
      memberTrueName: '',
      gender: 0,
      sexArray: ['保密', '男', '女'],
      memberBirthday: '',
      memberBirthdayCon: '请选择生日',
      endtime: new Date().getTime(),
      filters,
	  auditShow:false,
    }
  },
  onLoad() {
    this.getMmeberInfo()
  },
  onShow() {
  	let _this = this;
	// this.getAudit()
  	
  },
  computed: {
    ...mapState(['userInfo', 'userCenterData'])
  },
  methods: {
    ...mapMutations(['setUserCenterData']),
	//获取微信审核开关
	getAudit(){
	    let param = {};
		param.url='v3/system/front/configuration/1'
		this.$request(param).then(res=>{
			console.log(res);
			this.auditShow=res.data.auditSwitch
			
		})
	},
    //获取会员信息
    getMmeberInfo() {
      let _this = this
      this.$request({
        url: 'v3/member/front/member/memberInfo',
        method: 'GET'
      })
        .then((res) => {
          if (res.state == 200) {
            let result = res.data
            _this.memberAvatar = result.memberAvatar
            _this.memberName = result.memberName
            _this.memberNickName = result.memberNickName
            _this.gender = result.gender
            _this.memberBirthdayCon = result.memberBirthday
              ? result.memberBirthday
              : '请选择生日'
            this.memberTrueName = result.memberTrueName
			_this.setUserCenterData(result)
          } else {
            this.$modal.msg(res.msg)
          }
        })
        .catch((e) => {})
    },
   
    //选择生日
    selBirthDay(e) {
      this.saveMemInfo('memberBirthday', e.detail.value)
    },
    //选择性别
    selSex(e) {
      this.saveMemInfo('gender', e.detail.value)
    },
    //更新会员昵称
    updateMemInfo(index, val) {
      
    },
    //保存会员信息
    saveMemInfo(index, val) {
      if (val == this[index]) {
        return
      }

      let param = {}
      param.url = 'v3/member/front/member/updateInfo'
      param.data = {}
      param.method = 'POST'
      param.data[index] = val
      this.$request(param)
        .then((res) => {
          this.$modal.msg(res.msg)
          if (res.state != 200) {
            this.$modal.msg(res.msg)
          } else {
			  this.getMmeberInfo()
          }
        })
        .catch((e) => {
          //异常处理
        })
    },
    //设置头像
    setAvatar() {
	 
      let _this = this
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        success: function (res) {
          uni.showLoading({
            title: '上传中...'
          })
          if (res.tempFiles[0].size > Math.pow(1024, 2) * 4) {
            uni.hideLoading()
            uni.showToast({
              title: '超出了图片大小限制4M',
              icon: 'none',
              duration: 700
            })
          } else {
            uni.uploadFile({
              url: getApp().globalData.baseUrl + 'v3/oss/front/upload',
              filePath: res.tempFilePaths[0],
              name: 'file',
              formData: {
                source: 'headImg'
              },
              header: {
                  Authorization:  'Bearer '+_this.userInfo.access_token
               },
              success: (uploadFileRes) => {
                // #ifdef  MP-ALIPAY||MP-BAIDU
                let result = uploadFileRes.data
                // #endif

                // #ifndef MP-ALIPAY||MP-BAIDU
                let result = JSON.parse(uploadFileRes.data)
                // #endif
                if (result.state == 200) {
                  uni.hideLoading()
                  // _this.memberAvatarLocal = result.data.url
                  _this.saveMemInfo('memberAvatar', result.data.url)
                } else {
                  uni.hideLoading()
                  uni.showToast({
                    title: uploadFileRes.msg,
                    icon: 'none',
                    duration: 700
                  })
                }
              },
              fail: (uploadFileRes) => {
                uni.showToast({
                  title: uploadFileRes.msg,
                  icon: 'none',
                  duration: 700
                })
              }
            })
          }
        }
      })
    },
    //修改昵称事件
    changeName(type) {
     
    }
  }
}
</script>

<style lang="scss">
page {
  background: #f2f2f2;
  width: 750rpx;
  margin: 0 auto;
}

.list_cell {
  display: flex;
  align-items: center;
  padding: 0 20rpx;
  line-height: 100rpx;
  height: 100rpx;
  position: relative;
  background: #fff;
  justify-content: center;

  &.cell_hover {
    background: #fafafa;
  }

  &.b_b:after {
    left: 20rpx;
  }

  &.m_t {
    margin-top: 20rpx;
  }

  .cell_more {
    color: #949494;
    font-size: 18rpx;
    margin-left: 10rpx;
  }

  .cell_tit {
    flex: 1;
    font-size: 28rpx;
    color: #2d2d2d;
    margin-right: 10rpx;
  }

  .cell_right_con,
  .uni_birthday {
    color: #949494;
    font-size: 26rpx;
  }

  &.mem_avatar_wrap {
    height: 120rpx;
    line-height: 120rpx;
  }

  .avatar {
    width: 82rpx;
    height: 82rpx;
    border-radius: 50%;
    background-position: center center;
    background-repeat: no-repeat;
    background-color: #f8f6f7;
  }
}
</style>
